<template>
	<view class=" ">
		<view class="flex  a-c f28 bb p3">
			<view class="" style="width: 160rpx;">
				<text class="">手机号:</text>
			</view>
			<text class=" " style="line-height: 30rpx;">{{find.tel}}</text>
		</view>
		<view class="flex j-b a-c f28 bb p3" v-if="sms_img_code==1">
			<view class="flex a-c ">
				<view class="" style="width: 160rpx;">
					<text class="f28 ">图形验证码:</text>
				</view>
				<view class="" style="flex:1;">
					<input class="p1 f28  input_t" placeholder-class="my-input-placeholder" type="text" v-model="v_code"
						placeholder="请输入图形验证码" />
				</view>


			</view>
			<view class="f28 ml1" @tap="get_imgCode" style="width: 120px;">
				<image style="width: 120px;height: 32px;" :src="code_img" mode=""></image>
			</view>
		</view>
		<view class="flex j-b a-c f28 bb p3">
			<view class="flex a-c">
				<view class="" style="width: 160rpx;">
					<text class="f28 ">短信验证码:</text>
				</view>
				<view class="" style="flex:1;">
					<input class="p1 f26  input_t" placeholder-class="my-input-placeholder" type="text"
						v-model="checknum" placeholder="请输入短信验证码" />
				</view>

			</view>

			<view class="f28 " @tap="getCheckNum">
				<text>{{!codetime?'获取验证码':codetime+' s'}}</text>
			</view>
		</view>
		<view class="bb p3">
			<view class="flex a-c ">
				<view class="" style="width: 160rpx;">
					<text>输入新密码:</text>
				</view>
				<view class="" style="flex:1;">
					<input class="p1 f26  input_t" placeholder-class="my-input-placeholder" type="text" v-model="pass"
						placeholder="请输入新密码" />
				</view>
			</view>
		</view>
		<view class="bb p3">
			<view class="flex a-c ">
				<view class="" style="width: 160rpx;">
					<text class="f28">确认新密码:</text>
				</view>
				<view class="" style="flex:1;">
					<input class="p1 f26  input_t" placeholder-class="my-input-placeholder" type="text"
						v-model="newspass" placeholder="请输入确认新密码" />
				</view>
			</view>
		</view>
		<view class="flex j-c " style="padding-top: 80rpx;">
			<text @click="ok" class="flex a-c j-c  button_bg b_y " style="width: 90%;height: 70rpx;">确认修改</text>
		</view>
	</view>
</template>

<script>
	export default {

		data() {
			return {
				flag: false,
				codetime: 0,
				find: {},
				pass: '',
				newspass: '',
				checknum: '',
				post: false,
				code_img: '',
				v_code: '',
				sms_img_code: ''

			}
		},
		onLoad() {
			this.token = uni.getStorageSync('token');

			if (this.token) {
				this.init();
			}
		},
		methods: {
			init() {
				let RandomSixStr = ''
				for (let i = 0; i < 10; i++) {
					RandomSixStr += String(Math.floor(Math.random() * 10))
				}
				this.v_id = RandomSixStr;
				const user_id = uni.getStorageSync('user_id');
				const token = uni.getStorageSync('token');
				let requestParams = {
					user_id: user_id,
					token: token
				};
				this.Http.post('/banmi.php/User/index', requestParams).then(ret => {

					if (ret.status == 200) {
						this.find = ret.data.user;
						this.code_img_a = ret.code_img;
						this.sms_img_code = ret.sms_img_code;
						this.code_img = ret.code_img + '?id=' + RandomSixStr;
					
					}
				})

			},
			get_imgCode() {
				let RandomSixStr = ''
				for (let i = 0; i < 10; i++) {
					RandomSixStr += String(Math.floor(Math.random() * 10))
				}
				this.v_id = RandomSixStr;
				this.code_img = this.code_img_a + '?id=' + RandomSixStr;

			},
			ok() {
				// #ifndef APP-PLUS
				// if (!this.flag) {
				// 	uni.showToast({
				// 		title: '请先滑动验证',
				// 		icon: "none"
				// 	});
				// 	return;
				// }
				if (!this.post) {
					uni.showToast({
						title: '请获取短信验证码',
						icon: "none"
					});
					return;
				}
				// #endif
				if (!this.checknum) {
					uni.showToast({
						title: '请输入短信验证码',
						icon: "none"
					});
					return;
				}
				if (!this.pass) {
					uni.showToast({
						title: '请输入新密码',
						icon: "none"
					});
					return;
				}
				if (!this.newspass) {
					uni.showToast({
						title: '请输入确认新密码',
						icon: "none"
					});
					return;
				}
				if (this.newspass != this.pass) {
					uni.showToast({
						title: '新密码和确认密码不一致',
						icon: "none"
					});
					return;
				}

				const user_id = uni.getStorageSync('user_id');
				const token = uni.getStorageSync('token');
				let requestParams = {
					checknum: this.checknum,
					newspass: this.newspass,
					pass: this.pass,
					user_id: user_id,
					token: token,
				};

				this.Http.post('banmi.php/User/LoginPass',requestParams).then(ret => {

					uni.showToast({
						title: ret.msg,
						icon: 'none'
					});
					if (ret.status == 200) {
						setTimeout(function() {
							uni.navigateBack();
						}, 500);
					}
				})
			},
			verifyResult(res) {

				this.flag = res.flag;
				this.resultData = res;
			},
			getCheckNum() {

				if (this.codetime > 0) {
					return;
				}
				// #ifndef APP-PLUS
				// if (!this.flag) {
				// 	uni.showToast({
				// 		title: '请先滑动验证',
				// 		icon: "none"
				// 	});
				// 	return;
				// }
				// #endif

		 
				let requestParams = {
					phone: this.find.tel,
			 
					pwa_id: 1,
					v_code: this.v_code,
					id: this.v_id
				};
				this.Http.post('banmi.php/Sms/TelMessage', requestParams).then(ret => {
					if (ret.status == 200) {
						this.post = true;
						uni.showToast({
							title: '发送成功',
							icon: 'none'
						});
						this.codetime = 60;
						let timer = setInterval(() => {
							this.codetime--;
							if (this.codetime < 1) {
								clearInterval(timer);
								this.codetime = 0;
							}
						}, 1000);
					} else {
						uni.showToast({
							title: ret.msg,
							icon: 'none'
						});
					}
				})


			},
		}
	}
</script>

<style>
	.input_t {
		width: 100%;
		height: 60rpx;
	}
</style>